<template>
    <div class="Header">
        <div class="left">
            <div class="title">助农扶农后台管理系统</div>
            <!-- <el-button class="btn" icon="el-icon-menu" @click="show"></el-button> -->
        </div>
        <div class="right">
            <span class="name">{{ this.name }}</span>
            <div class="img" v-if="token">
                <el-dropdown trigger="click" @command="exit">
                    <img :src="image" alt="">
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item command="a">切换账号</el-dropdown-item>
                        <el-dropdown-item command="b">退出</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: "myHeader",
    data() {
        return {
            token: '',
            name: '',
            image: '',
            flag: true
        }
    },
    methods: {
        // show() {

        // },
        login() {
            this.$router.push("/login")
        },
        exit(command) {
            if (command == 'a') {
                sessionStorage.removeItem("token")
                this.$message('退出成功!');
                this.$router.push("/login")
            }
            if (command == 'b') {
                sessionStorage.removeItem("token")
                localStorage.removeItem("name")
                localStorage.removeItem("image")
                this.$message('退出成功!');
                this.$router.push("/login")
            }
        }
    },
    mounted() {
        this.token = sessionStorage.getItem('token')
        this.name = localStorage.getItem('name')
        this.image = localStorage.getItem('image')
    }
}
</script>

<style scoped>
.Header {
    display: flex;
    justify-content: space-between;
}

.left {
    display: flex;
}

.title {
    margin-left: 30px;
    line-height: 60px;
    font-size: 26px;
    color: #ccc;
}

.btn {
    padding: 0;
    height: 30px;
    width: 40px;
    margin-left: 30px;
    margin-top: 17px;
}

.img {
    margin-top: 12px;
    width: 40px;
    height: 40px;
    margin-right: 30px;
    /* background-color: aquamarine; */
    border-radius: 10000px;
    overflow: hidden;
}

.el-dropdown {
    width: 40px;
    height: 40px;
}

img {
    width: 100%;
    height: 100%;
}

.right {
    display: flex;
}

.name {
    margin-right: 30px;
    line-height: 60px;
    font-size: 18px;
    color: #ccc;
    font-weight: 700;
}
</style>